package cn.fay.chapter13;

import java.io.StringReader;
import java.util.Scanner;
import java.util.regex.MatchResult;

public class MultiType {

	private int i;
	private long l;
	private float f;
	private double d;
	private String str;
	
	public MultiType(String str){
		this.str=str;
	}
	public void put2Type(){
		StringReader sr=new StringReader(str);
		Scanner scanner=new Scanner(sr);
		scanner.useDelimiter("\\s*,\\s*");
		i=scanner.nextInt();
		l=scanner.nextLong();
		f=scanner.nextFloat();
		d=scanner.nextDouble();
	}
	public void nextE(){
		Scanner scanner=new Scanner(str);
		while(scanner.hasNext()){
			scanner.next();
			MatchResult match = scanner.match();
			System.out.println(match.group());
		}
	}
	

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "i="+i+"\tl="+l+"\tf="+f+"\td="+d;
	}
	public static void main(String[] args) {
		String string="1234,876776556,873.99873,9876.00987763";
		MultiType multiType=new MultiType(string);
		multiType.put2Type();
		System.out.println(multiType);
		multiType.nextE();
	}

}
